"==============================================================================
" filetype 文件识别，添加文件头
"==============================================================================
filetype on
autocmd BufNewFile *.sh   exec ":call SetSHTitle()" 
autocmd BufNewFile *.c,   exec ":call SetCTitle()" 
autocmd BufNewFile *.cpp, exec ":call SetCPPTitle()" 
autocmd BufNewFile *.h,   exec ":call SetHTitle()" 
autocmd BufNewFile *.md,  exec ":call SetMDTitle()" 
""定义函数SetTitle，自动插入文件头 
func SetSHTitle() 
    call setline(1,          "#*  @file         ".expand("%"))
    call append(line(".")+0, "#*  @brief        简要说明")
    call append(line(".")+1, "#*  @details      详细说明") 
    call append(line(".")+2, "#*  @author       lzm")
    call append(line(".")+3, "#*  @date         ".strftime("%Y-%m-%d %H:%M:%S")) 
    call append(line(".")+4, "#*  @version      v1.0") 
    call append(line(".")+5, "#*  @copyright    Copyright By lizhuming, All Rights Reserved") 
    call append(line(".")+6, "#*")
    call append(line(".")+7, "#**********************************************************")
    call append(line(".")+8, "#*  @LOG 修改日志:")
    call append(line(".")+9, "#**********************************************************")
    call append(line(".")+10,"#*/")
    call append(line(".")+11,"")
	call append(line(".")+12,"#!/bin/sh")
	call append(line(".")+13, "")
	endif
endfunc 
func SetCTitle() 
    call setline(1,         "/** @file         ".expand("%"))
    call append(line(".")+0, " *  @brief        简要说明")
    call append(line(".")+1, " *  @details      详细说明") 
    call append(line(".")+2, " *  @author       lzm")
    call append(line(".")+3, " *  @date         ".strftime("%Y-%m-%d %H:%M:%S")) 
    call append(line(".")+4, " *  @version      v1.0") 
    call append(line(".")+5, " *  @copyright    Copyright By lizhuming, All Rights Reserved") 
    call append(line(".")+6, " *")
    call append(line(".")+7, " **********************************************************")
    call append(line(".")+8," *  @LOG 修改日志:")
    call append(line(".")+9," **********************************************************")
    call append(line(".")+10,"*/")
    call append(line(".")+11,"")
	call append(line(".")+12,"#include <stdio.h>")
	call append(line(".")+13,"")
endfunc 
func SetSCPPTitle() 
    call setline(1,         "/** @file         ".expand("%"))
    call append(line(".")+0, " *  @brief        简要说明")
    call append(line(".")+1, " *  @details      详细说明") 
    call append(line(".")+2, " *  @author       lzm")
    call append(line(".")+3, " *  @date         ".strftime("%Y-%m-%d %H:%M:%S")) 
    call append(line(".")+4, " *  @version      v1.0") 
    call append(line(".")+5, " *  @copyright    Copyright By lizhuming, All Rights Reserved") 
    call append(line(".")+6, " *")
    call append(line(".")+7, " **********************************************************")
    call append(line(".")+8," *  @LOG 修改日志:")
    call append(line(".")+9," **********************************************************")
    call append(line(".")+10,"*/")
    call append(line(".")+11,"")
	call append(line(".")+12,"#include <stdio.h>")
	call append(line(".")+13,"")
endfunc 
func SetHTitle() 
    call setline(1,         "/** @file         ".expand("%"))
    call append(line(".")+0, " *  @brief        简要说明")
    call append(line(".")+1, " *  @details      详细说明") 
    call append(line(".")+2, " *  @author       lzm")
    call append(line(".")+3, " *  @date         ".strftime("%Y-%m-%d %H:%M:%S")) 
    call append(line(".")+4, " *  @version      v1.0") 
    call append(line(".")+5, " *  @copyright    Copyright By lizhuming, All Rights Reserved") 
    call append(line(".")+6, " *")
    call append(line(".")+7, " **********************************************************")
    call append(line(".")+8," *  @LOG 修改日志:")
    call append(line(".")+9," **********************************************************")
    call append(line(".")+10,"*/")
    call append(line(".")+11,"")
	call append(line(".")+12,"#ifndef __".expand("%:r")."__")
	call append(line(".")+13,"#define __".expand("%:r")."__")
	call append(line(".")+14,"")
	call append(line(".")+15,"#endif /* Head define end*/")
	call append(line(".")+16,"")
endfunc 
func SetMDTitle() 
    call setline(1, "---") 
    call append(line(".")+0, "title: ".expand("%:r")) 
    call append(line(".")+1, "date: ".strftime("%Y-%m-%d %H:%M:%S")) 
    call append(line(".")+2, "categories: ") 
    call append(line(".")+3, "tags: ")
    call append(line(".")+4, "---")
    call append(line(".")+5, "")
endfunc 


"==============================================================================
" set 一般设置
"==============================================================================
set nocompatible                "不兼容vi
syntax enable                   "语法高亮使能
syntax on                       "语法高亮开启
set hlsearch                    "开启高亮搜索
set incsearch                   "输出字符串的同时进行搜索
set ignorecase                  "搜索时忽略大小写
set ruler                       "右下角的状态栏下显示光标的坐标
set showcmd                     "显示normal模式下的命令
set number                      "显示行号
set relativenumber              "相对行号
set cmdheight=1                 "命令行高度为1行"
set noshowmode                  "不显示'-- insert --' 等
set autoindent                  "自动缩进
set smartindent                 "智能缩进
set cindent                     "c语言缩进
set pastetoggle=<F4>            "系统paste
set mouse=i                     "仅在insert mode 下可使用mouse

set autoread                    "当文件在外部被改变时, vim自动载入
set showmatch                   "显示匹配的括号
set matchtime=0                 "显示匹配的括号的时间，单位：十分之一秒
set t_Co=256                    "vim配色为256色
set cursorline                  "高亮当前光标行
set cursorcolumn                "高亮当前光标列
autocmd InsertEnter * se cul
set shortmess=atI
set scrolloff=3                 "光标移动到buffer的顶部和底部时保持3行距离
set laststatus=2                "指定什么时候对最后一个窗口显示状态条, 2表示永远有
set cinoptions=g0,:0,N-s,(0     "设置C/C++语言的具体缩进方式, unkown
set tabstop=4                   "读取到文件的\t时，解释的空白长度
set softtabstop=4               "在编辑动作（按tab或backspace键）时，所输入或删除的空白长度
set shiftwidth=4                "自动缩进时的空白长度
set expandtab                   "将tab转换成space，文件中存储的将会是space
set smarttab
" set list                        "显示tab键为^I, 行为显示$
set listchars=tab:>-,trail:-    "tab显示为">---" 行尾多余的空白字符显示为"-"
set history=1000                "命令历史个数
set langmenu=en_US.UTF-8        "菜单语系
set helplang=en                 "使用中文文档cn，英文则为en
set autowrite                   "自动保存, 否则切换buffer,文件后会会提示没有保存
set magic                       "匹配正则表达式时(\m)：除了$.*^之外其他正则表达式的元字符都要加反斜杠\
set confirm                     "总是出现确认选项，如执行:qa等命令时
set nobackup                    "vim当覆盖一个文件时不保留一个备份
set noswapfile                  "不使用交换空间
set wildmenu                    "补全相关，unkown
set completeopt=longest,menu    "显示补全列表
set backspace=indent,eol,start  "indent将4个空格缩进当缩进删除，eol删除到上一行
set report=0                    "当使用:commands命令时，总是报告文件的那一行被改变过
set fillchars=vert:\ ,stl:\ ,stlnc:\  "设置多窗口时的窗口间分割线
" set iskeyword+=.                "追加.为判断一个word
set termencoding=utf-8          "终端使用的字符编码
set encoding=utf8               "vim内部buffer使用的字符编码
set fileencodings=utf8,ucs-bom,gbk,cp936,gb2312,gb18030 "依次判断文件字符编码
" set foldmethod=indent         "基于缩进的折叠
set foldmethod=syntax           "基于语法的折叠
set nofoldenable                "启动 vim 时关闭折叠代码
" set nowrap                      "禁止折行
set viminfo+=n~/.cache/vim/.viminfo

let $BASH_ENV="~/.bash_aliases" "增加外部命令的alias
let mapleader = ","             "修改<leader>键为','
vnoremap <leader>y "+y

filetype plugin on              "根据文件类型读取插件
filetype indent on              "使用缩进文件

" 标签跳转快捷键，在gnome-terminal中无效
" normal no recursive map
" insert no recursive map
nnoremap <C-c> :tabclose<cr>
nnoremap <C-x> :tabonly<cr>
nnoremap <C-k> :tabs<cr>
nnoremap <C-n> :tabnew<cr>
nnoremap <C-h> :tabprevious<cr>
nnoremap <C-l> :tabnext<cr>

" 光标闪烁，在插入模式下为‘|’，在norrmal 模式下为方块
" 若要不闪烁，则将改为后面的数字
let &t_SI = "\<Esc>[5 q"                     " 6
let &t_SR = "\<Esc>[3 q"                     " 4
let &t_EI = "\<Esc>[1 q"                     " 2


"==============================================================================
" Vundle start  插件管理
"==============================================================================
"filetype off                    " 必须的

" 设置包括vundle和初始化相关的runtime path

" 例子+格式开始==================================================
" 插件的命令放在vundle#begin和vundle#end之间.
" 1.Github上的插件
" 格式为 Plugin '用户名/插件仓库名'
"Plugin 'tpope/vim-fugitive'
" 2.来自 http://vim-scripts.org/vim/scripts.html 的插件
" Plugin '插件名称' 实际上是 Plugin 'vim-scripts/插件仓库名' 只是此处的用户名可以省略
"Plugin 'L9'
" 3.由Git支持但不再github上的插件仓库 Plugin 'git clone 后面的地址'
"Plugin 'git://git.wincent.com/command-t.git'
" 4.本地的Git仓库(例如自己的插件) Plugin 'file:///+本地插件仓库绝对路径'
"Plugin 'file:///home/gmarik/path/to/plugin'
" 5.插件在仓库的子目录中.
" 正确指定路径用以设置runtimepath. 以下范例插件在sparkup/vim目录下
"Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
" 6.安装L9，如果已经安装过这个插件，可利用以下格式避免命名冲突
"Plugin 'ascenator/L9', {'name': 'newL9'}
" 例子+格式END ==================================================


set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()                             " 必须 插件开始==================================================

Plugin 'VundleVim/Vundle.vim'                   " 必须 让vundle管理插件版本
Plugin 'Yggdroot/indentLine'                    "缩进指示线
"Plugin 'suan/vim-instant-markdown'             " markdown实时浏览
Plugin 'vim-airline/vim-airline'                "美观界面，powerline
"Plugin 'fatih/vim-go'
" 由Git支持但不再github上的插件仓库 Plugin 'git clone 后面的地址'
Plugin 'L9'
Plugin 'terryma/vim-multiple-cursors'   " 多光标输入
Plugin 'jiangmiao/auto-pairs'                   "自动补全括号对。输入`[`, 会自动输入']' "<c-h> 会被映射为 <DELETE>，如需用到，可以注释掉
"Plugin 'tpope/vim-commentary'                   "注释插件：gcc
Plugin 'scrooloose/nerdtree'                    "目录树
Plugin 'Valloric/YouCompleteMe'
"Plugin 'rdnetto/YCM-Generator'                  "YouCompleteMe 配置生成器
"Plugin 'vim-scripts/SQLComplete.vim'
"Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}      "html 快捷键
Plugin 'Valloric/MatchTagAlways'                "html, xml显示匹配标签：<leader>%
Plugin 'docunext/closetag.vim'                  "html, xml闭合标签，<C-_> 不起作用
Plugin 'godlygeek/tabular'                      "文本对齐：:Tab /=  、 :Tab /|
"Plugin 'tpope/vim-fugitive'                     "在vim中可以执行简单git命令
Plugin 'tpope/vim-surround'                     "方便修改增加括号对
Plugin 'tpope/vim-repeat'
Plugin 'tpope/vim-endwise'                      "在c中补全#if中的#endif等
Plugin 'ctrlpvim/ctrlp.vim'                     "搜索文件<C-f>
Plugin 'majutsushi/tagbar'                      "显示ctags
Plugin 'octol/vim-cpp-enhanced-highlight'       "C++增强高亮
"Plugin 'vim-airline/vim-airline-themes'         "美观界面，powerline
"Plugin 'ryanoasis/vim-devicons'                 "美化界面
"Plugin 'gorodinskiy/vim-coloresque'             "颜色，如 blue #00f
"Plugin 'will133/vim-dirdiff'                    "可以比较目录
Plugin 'haya14busa/incsearch.vim'               "同时高亮匹配所有的字符
Plugin 'mhinz/vim-startify'                     "终端运行直接运行vim时显示的菜单界面
Plugin 'mileszs/ack.vim'                        "ag命令

Plugin 'davidhalter/jedi-vim'                   "python
"Plugin 'Shougo/echodoc.vim'                     "显示命令参数

filetype plugin indent on                       " 必须 加载vim自带和插件相应的语法和文件类型相关脚本
call vundle#end()                               " 必须 插件END ==================================================


"filetype plugin on                     " 忽视插件改变缩进

"==============================================================================
" nerdtree
"==============================================================================
map <F2> :NERDTreeToggle<CR>
imap <F2> <ESC> :NERDTreeToggle<CR>

"autocmd vimenter * if !argc() | NERDTree | endif
"autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
"ctrl+h 为左方向键
imap <C-h> <LEFT>
"ctrl+l 为右方向键
imap <C-l> <RIGHT>
"ctrl+k 为上方向键
imap <C-k> <UP>
"ctrl+j为下方向键
imap <C-j> <DOWN>
"ctrl+d为删除键
imap <C-d> <DELETE>

"==============================================================================
" YouCompleteMe
"==============================================================================
let g:ycm_global_ycm_extra_conf = '~/.ycm_extra_conf.py' "全局配置文件
let g:ycm_confirm_extra_conf = 0                        "加载配置文件时不需要手动确认
let g:ycm_error_symbol = '✗'                            "error 符号
let g:ycm_warning_symbol = '⚠'                          "warning符号
let g:ycm_seed_identifiers_with_syntax = 1              "关键字补全
let g:ycm_complete_in_comments = 1                      "在注释输入中可以补全
let g:ycm_complete_in_strings = 1                       "在字符串输入中可以补全
let g:ycm_key_invoke_completion = '<C-n>'               "更改手动触发补全按键，默认<C-space>
let g:ycm_collect_identifiers_from_tags_files = 1       "开启基于tag的补全
let g:ycm_key_list_select_completion = ['<Down>']       "取消'<Tab>'
" let g:ycm_auto_trigger = 0                              "不会自动补全, 需要按下<C-n>
" let g:ycm_semantic_triggers = {}
" let g:ycm_semantic_triggers.c = ['->', '.', ' ', '(', '[', '&',']']

nnoremap <leader>u :YcmCompleter GoToDeclaration<CR>    "跳到声明处
nnoremap <leader>o :YcmCompleter GoToDefinition<CR>     "跳到定义处
nnoremap <leader>i :YcmCompleter GoToInclude<CR>        "跳到头文件
"nmap <F5> :YcmDiags<CR>                                 "自定义快捷键<F5>显示警告和错误的信息

"let g:ycm_add_preview_to_completeopt = 1                "关闭打开一个窗口显示预览
"let g:ycm_autoclose_preview_window_after_completion = 0 "即自动关闭预览窗口
"let g:ycm_autoclose_preview_window_after_insertion = 1  "自动关闭预览窗口在回到normal模式后
"let g:ycm_cache_omnifunc = 0                            "每次重新生成匹配项，禁止缓存匹配项

" tagbar
let g:tagbar_ctags_bin = '/usr/bin/ctags'
let g:tagbar_width = 30
map <F3> :TagbarToggle<CR>
imap <F3> <ESC> :TagbarToggle<CR>

" cpp_class_scope_highlight
let g:cpp_class_scope_highlight = 1
let g:cpp_experimental_template_highlight = 1
let c_no_curly_error = 1

" colorscheme
"colorscheme default
" colorscheme monokai
"let g:solarized_termcolors=256
"set background=light                "设置深色的背景色, 该命令需要在systax enable后调用
"colorscheme solarized               "设置色彩方案为solarized



"==============================================================================
" Other
"==============================================================================
let g:airline#extensions#tabline#enabled = 1
if !exists('g:airline_symbols')
    let g:airline_symbols = {}
endif


